package com.meirengu.webview.service.impl;

import com.meirengu.service.impl.BaseServiceImpl;
import com.meirengu.webview.dao.KwHandleInfoDao;
import com.meirengu.webview.model.KwHandleInfo;
import com.meirengu.webview.service.KwHandleInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * KwHandleInfo服务实现层
 *
 * @author Mao
 * @create Wed Apr 18 14:42:35 CST 2018
 */
@Service
public class KwHandleInfoServiceImpl extends BaseServiceImpl<KwHandleInfo> implements KwHandleInfoService {


    @Autowired
    KwHandleInfoDao kwHandleInfoDao;


    /**
     * 根据key查找
     *
     * @param key
     * @return
     */
    public KwHandleInfo detailByKey(String key) {
        return kwHandleInfoDao.detailByKey(key);
    }

    /**
     * 添加处理记录
     *
     * @param key
     */
    public void addHandle(String key) {
        KwHandleInfo kwHandleInfo = new KwHandleInfo();
        kwHandleInfo.setOriginCode("1");
        kwHandleInfo.setOriginName("MQ");
        kwHandleInfo.setKeySn(key);
        kwHandleInfo.setStatusCode("1");
        insert(kwHandleInfo);
    }

    /**
     * 更新处理状态
     *
     * @param id
     * @param status
     */
    public void updateStatus(String id, String status) {
        KwHandleInfo kwHandleInfo = new KwHandleInfo();
        kwHandleInfo.setId(id);
        kwHandleInfo.setStatusCode(status);
        if ("3".equals(status)) {
            kwHandleInfo.setFinishTime(new Date());
        } else {
            kwHandleInfo.setUpdateDate(new Date());
        }
        update(kwHandleInfo);
    }

}
